﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Profiles;
using Styx.WoWInternals;

//
// TODO
// -PetsAlive EnemyPetsAlive
//


namespace BattleBuddyplug
{
    partial class configForm
    {
        string[] logictags = { "Unknown", "Simple Leveling", "Boost Leveling", "Max Lvl", "Ringer", "PVP", "Survival" };
        DataTable table = new DataTable();
        int initdone = 0;
        private void BlacklistSave()
        {
            lstNeverAttackItems.Sorted = true;

            StreamWriter Write;
            try
            {
                Write = new StreamWriter(BattleBuddy._BlacklistPath);
                for (int I = 0; I < lstNeverAttackItems.Items.Count; I++)
                {
                    Write.WriteLine(Convert.ToString(lstNeverAttackItems.Items[I]));
                }
                Write.Close();
            } catch (Exception exc) {
                BBLog.LogException(exc);
                return;
            }
            BattleBuddy.BlacklistLoad();

        }



        private void MacroSave()
        {
        }



        public static DialogResult InputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = title;
            label.Text = promptText;
            textBox.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 20, 372, 13);
            textBox.SetBounds(12, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            label.AutoSize = true;
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            value = textBox.Text;
            return dialogResult;
        }



        public static DialogResult MultiInputBox(string title, string promptText, ref string value)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = title;
            label.Text = promptText;
            textBox.Multiline = true;
            textBox.Text = value;

            buttonOk.Text = "OK";
            buttonCancel.Text = "Cancel";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;

            label.SetBounds(9, 20, 372, 13);
            textBox.SetBounds(12, 36, 372, 20);
            buttonOk.SetBounds(228, 72, 75, 23);
            buttonCancel.SetBounds(309, 72, 75, 23);

            label.AutoSize = true;
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 107);
            form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
            form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;

            DialogResult dialogResult = form.ShowDialog();
            value = textBox.Text.Replace(Environment.NewLine, "");
            return dialogResult;
        }



        private void BlacklistLoad()
        {
            lstNeverAttackItems.Items.Clear();

            try
            {
                StreamReader Read = new StreamReader(Convert.ToString(BattleBuddy._BlacklistPath));
                while (Read.Peek() >= 0)
                {
                    string pline = Read.ReadLine();
                    if (pline != null)
                    {
                        lstNeverAttackItems.Items.Add(pline.ToLower());

                    }
                }
                Read.Close();
            }
            catch (Exception exc)
            {
                BBLog.LogException(exc);
                return;
            }
            BattleBuddy.BlacklistLoad();
        }



        public void WhiteListAdd(string item)
        {
            var match = lstAttackOnlyItems.FindString(item);
            if (match == ListBox.NoMatches) {
                lstAttackOnlyItems.Items.Add(item);
                WhitelistSave();
            }
        }



        private void WhitelistSave()
        {
            lstAttackOnlyItems.Sorted = true;

            StreamWriter Write;
            try
            {
                Write = new StreamWriter(BattleBuddy._WhitelistPath);
                for (int I = 0; I < lstAttackOnlyItems.Items.Count; I++)
                {
                    Write.WriteLine(Convert.ToString(lstAttackOnlyItems.Items[I]));
                }
                Write.Close();
            }
            catch (Exception exc)
            {
                BBLog.LogException(exc);
            }
            BattleBuddy.WhitelistLoad();
        }



        private void WhitelistLoad()
        {
            lstAttackOnlyItems.Items.Clear();

            try
            {
                StreamReader Read = new StreamReader(Convert.ToString(BattleBuddy._WhitelistPath));
                while (Read.Peek() >= 0)
                {
                    string pline = Read.ReadLine();
                    if (pline != null)
                    {
                        lstAttackOnlyItems.Items.Add(pline.ToLower());

                    }
                }
                Read.Close();
            }
            catch (Exception exc)
            {
                BBLog.LogException(exc);
            }
            BattleBuddy.WhitelistLoad();
        }



        private void configForm_Load(object sender, EventArgs e)
        {
            LoadDefaults();
            BlacklistLoad();
            WhitelistLoad();
            GetQuickSettings();
            listView2.Items.Clear();
            foreach (string s in logictags)
            {
                listView2.Items.Add(s);
            }

            this.groupBox10.Location = new System.Drawing.Point(6, 287);
            this.groupBox16.Location = new System.Drawing.Point(3, 287);
            toolTip1.SetToolTip(this.textBox11, "Complicated, will think of this later");

            cbAutoUpdate.Checked = BattleBuddy._MySettings.AllowAutoUpdate;

            txtRatingHealthFormula.Text = BattleBuddy._MySettings.HPFormula;
            txtRatingAdvantageFormula.Text = BattleBuddy._MySettings.AdFormula;
            txtRatingDisadvantageFormula.Text = BattleBuddy._MySettings.DisFormula;
            txtRatingLevelFormula.Text = BattleBuddy._MySettings.LevelFormula;

            cbUseDenyList.Checked = BattleBuddy._MySettings.UseBlackList;
            cbUseAllowList.Checked = BattleBuddy._MySettings.UseWhiteList;

            cbPrecombatSwapping.Checked = BattleBuddy._MySettings.DoPreCombatSwapping;
            cbUseAdvancedRatingSystem.Checked = BattleBuddy._MySettings.UseRatingSystem;


            cbForfeitNonInteresting.Checked = BattleBuddy._MySettings.ForfeitIfNotInteresting;
            //checkBox3.Checked = BattleBuddy.MySettings.UseBandagesToHeal;

            cmbUseBandages.SelectedIndex = BattleBuddy._MySettings.UseBandagesToHeal;
            cmbUsePetHeal.SelectedIndex = BattleBuddy._MySettings.UseHealSkill;

            cbDetailedLogging.Checked = BattleBuddy._MySettings.DetailedLogging;

            trackBar1.Value = BattleBuddy._MySettings.HPFactor;
            trackBar2.Value = BattleBuddy._MySettings.LevelFactor;
            trackBar3.Value = BattleBuddy._MySettings.AdFactor;
            trackBar4.Value = BattleBuddy._MySettings.DisFactor;
            trkbarCombatDistance.Value = BattleBuddy._MySettings.Distance;

            checkBox1.Checked = BattleBuddy._MySettings.DoPVP;
            cmbBattleLowerLimit.SelectedIndex = BattleBuddy._MySettings.BelowLevel;
            cmbBattleUpperLimit.SelectedIndex = BattleBuddy._MySettings.AboveLevel;
            cmbMinPvpTime.SelectedIndex = BattleBuddy._MySettings.PVPMinTime;

            cmbDoNotEngage.SelectedIndex = BattleBuddy._MySettings.MinPetsAlive - 1;

            cmbMaxPvpTime.Items.Clear();


            int dummy = 0;
            for (int i = 1; i < 60; i++)
            {
                dummy = BattleBuddy._MySettings.PVPMinTime + 1;
                cmbMaxPvpTime.Items.Add(dummy + i);
            }


            cmbMaxPvpTime.SelectedIndex = BattleBuddy._MySettings.PVPMaxTime;

            lbRotationOrder.Items.Clear();

            string dumdum = BattleBuddy._MySettings.PetOrder;
            string[] orders = dumdum.Split(',');

            foreach (string order in orders)
            {
                lbRotationOrder.Items.Add(order);
            }

            cmbCapture.SelectedIndex = BattleBuddy._MySettings.GetRarity - 1;
            initdone = 1;
        }



        private void configForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            BlacklistSave();
            WhitelistSave();
            BattleBuddy._MySettings.HPFormula = txtRatingHealthFormula.Text;
            BattleBuddy._MySettings.AdFormula = txtRatingAdvantageFormula.Text;
            BattleBuddy._MySettings.DisFormula = txtRatingDisadvantageFormula.Text;
            BattleBuddy._MySettings.LevelFormula = txtRatingLevelFormula.Text;
            BattleBuddy._MySettings.Save();
        }



        private void cbExpertUnlock_CheckedChanged(object sender, System.EventArgs e)
        {
            txtRatingHealthFormula.Enabled = cbExpertUnlock.Checked;
            txtRatingAdvantageFormula.Enabled = cbExpertUnlock.Checked;
            txtRatingDisadvantageFormula.Enabled = cbExpertUnlock.Checked;
            txtRatingLevelFormula.Enabled = cbExpertUnlock.Checked;
        }



        private void checkBox9_CheckedChanged(object sender, System.EventArgs e)
        {
        }




        private void btnPetRatingPreviewRefresh_Click(object sender, System.EventArgs e)
        {
            if (cmbPetRatingPreviewLevel.SelectedIndex == -1) cmbPetRatingPreviewLevel.SelectedIndex = 0;
            if (cmbPetRatingPreviewSpecies.SelectedIndex == -1) cmbPetRatingPreviewSpecies.SelectedIndex = 0;
            loadpreviewimages();
            updatenumbers();
        }



        private int CalcLua(string s)
        {
            List<string> cnt = Lua.GetReturnValues("return (" + s + ")");
            return int.Parse(cnt[0]);
        }



        private void updatenumbersLua()
        {
            string s = "1 + 1 * 3";
            int value = 0;
            int advantage = 0;
            int disadvantage = 0;
            var total = 0;

            //pet 1
            total = 0;
            disadvantage = 0;
            advantage = 0;

            s = txtRatingHealthFormula.Text;
            s = s.Replace("petHP", BattleBuddy.GetPetHPPreCombat(1).ToString()).Replace("HPFactor", trackBar1.Value.ToString());

            value = CalcLua(s);
            total = value;
            label50.Text = value.ToString();

            int mypet = BattleBuddy.GetTypeByID(BattleBuddy.ReadSlot(1));
            if (mypet == BattleBuddy.DumbChoiceTakeMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = -2;
            if (mypet == BattleBuddy.DumbChoiceDealLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = disadvantage - 1;//rating -1;
            if (mypet == BattleBuddy.SmartChoiceTakeLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = 1;
            if (mypet == BattleBuddy.SmartChoiceDealMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = advantage + 2;
            s = txtRatingAdvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("advantage", advantage.ToString()).Replace("AdFactor", trackBar3.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label49.Text = value.ToString();

            s = txtRatingDisadvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("disadvantage", disadvantage.ToString()).Replace("DisFactor", trackBar4.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label48.Text = value.ToString();

            s = txtRatingLevelFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("petLevel", BattleBuddy.GetPetLevelPreCombat(1).ToString()).Replace("enemylevel", (cmbPetRatingPreviewLevel.SelectedIndex + 1).ToString()).Replace("LevelFactor", trackBar2.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label47.Text = value.ToString();

            label46.Text = total.ToString();

            //pet 2
            total = 0;
            disadvantage = 0;
            advantage = 0;

            s = txtRatingHealthFormula.Text;
            s = s.Replace("petHP", BattleBuddy.GetPetHPPreCombat(2).ToString()).Replace("HPFactor", trackBar1.Value.ToString());

            value = CalcLua(s);
            total = value;
            label56.Text = value.ToString();

            mypet = BattleBuddy.GetTypeByID(BattleBuddy.ReadSlot(2));
            if (mypet == BattleBuddy.DumbChoiceTakeMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = -2;
            if (mypet == BattleBuddy.DumbChoiceDealLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = disadvantage - 1;//rating -1;
            if (mypet == BattleBuddy.SmartChoiceTakeLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = 1;
            if (mypet == BattleBuddy.SmartChoiceDealMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = advantage + 2;
            s = txtRatingAdvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("advantage", advantage.ToString()).Replace("AdFactor", trackBar3.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label55.Text = value.ToString();

            s = txtRatingDisadvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("disadvantage", disadvantage.ToString()).Replace("DisFactor", trackBar4.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label54.Text = value.ToString();

            s = txtRatingLevelFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("petLevel", BattleBuddy.GetPetLevelPreCombat(2).ToString()).Replace("enemylevel", (cmbPetRatingPreviewLevel.SelectedIndex + 1).ToString()).Replace("LevelFactor", trackBar2.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label53.Text = value.ToString();

            label52.Text = total.ToString();

            //pet 3
            total = 0;
            disadvantage = 0;
            advantage = 0;

            s = txtRatingHealthFormula.Text;
            s = s.Replace("petHP", BattleBuddy.GetPetHPPreCombat(3).ToString()).Replace("HPFactor", trackBar1.Value.ToString());

            value = CalcLua(s);
            total = value;
            label62.Text = value.ToString();

            mypet = BattleBuddy.GetTypeByID(BattleBuddy.ReadSlot(3));
            if (mypet == BattleBuddy.DumbChoiceTakeMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = -2;
            if (mypet == BattleBuddy.DumbChoiceDealLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = disadvantage - 1;//rating -1;
            if (mypet == BattleBuddy.SmartChoiceTakeLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = 1;
            if (mypet == BattleBuddy.SmartChoiceDealMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = advantage + 2;
            s = txtRatingAdvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("advantage", advantage.ToString()).Replace("AdFactor", trackBar3.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label60.Text = value.ToString();

            s = txtRatingDisadvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("disadvantage", disadvantage.ToString()).Replace("DisFactor", trackBar4.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label59.Text = value.ToString();

            s = txtRatingLevelFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("petLevel", BattleBuddy.GetPetLevelPreCombat(3).ToString()).Replace("enemylevel", (cmbPetRatingPreviewLevel.SelectedIndex + 1).ToString()).Replace("LevelFactor", trackBar2.Value.ToString());

            value = CalcLua(s);
            total = total + value;
            label58.Text = value.ToString();

            label57.Text = total.ToString();
        }



        private void updatenumbers()
        {
            string s = "1 + 1 * 3";

            var value = BattleBuddy.Calculate(s);
            int advantage = 0;
            int disadvantage = 0;
            var total = 0;

            //pet 1
            total = 0;
            disadvantage = 0;
            advantage = 0;

            s = txtRatingHealthFormula.Text;
            s = s.Replace("petHP", BattleBuddy.GetPetHPPreCombat(1).ToString()).Replace("HPFactor", trackBar1.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = int.Parse(value.ToString());
            label50.Text = value.ToString();


            int mypet = BattleBuddy.GetTypeByID(BattleBuddy.ReadSlot(1));
            if (mypet == BattleBuddy.DumbChoiceTakeMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = -2;
            if (mypet == BattleBuddy.DumbChoiceDealLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = disadvantage - 1;//rating -1;
            if (mypet == BattleBuddy.SmartChoiceTakeLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = 1;
            if (mypet == BattleBuddy.SmartChoiceDealMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = advantage + 2;
            s = txtRatingAdvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("advantage", advantage.ToString()).Replace("AdFactor", trackBar3.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label49.Text = value.ToString();

            s = txtRatingDisadvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("disadvantage", disadvantage.ToString()).Replace("DisFactor", trackBar4.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label48.Text = value.ToString();

            s = txtRatingLevelFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("petLevel", BattleBuddy.GetPetLevelPreCombat(1).ToString()).Replace("enemylevel", (cmbPetRatingPreviewLevel.SelectedIndex + 1).ToString()).Replace("LevelFactor", trackBar2.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label47.Text = value.ToString();

            label46.Text = total.ToString();

            //pet 2
            total = 0;
            disadvantage = 0;
            advantage = 0;

            s = txtRatingHealthFormula.Text;
            s = s.Replace("petHP", BattleBuddy.GetPetHPPreCombat(2).ToString()).Replace("HPFactor", trackBar1.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = int.Parse(value.ToString());
            label56.Text = value.ToString();

            mypet = BattleBuddy.GetTypeByID(BattleBuddy.ReadSlot(2));
            if (mypet == BattleBuddy.DumbChoiceTakeMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = -2;
            if (mypet == BattleBuddy.DumbChoiceDealLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = disadvantage - 1;//rating -1;
            if (mypet == BattleBuddy.SmartChoiceTakeLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = 1;
            if (mypet == BattleBuddy.SmartChoiceDealMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = advantage + 2;
            s = txtRatingAdvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("advantage", advantage.ToString()).Replace("AdFactor", trackBar3.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label55.Text = value.ToString();

            s = txtRatingDisadvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("disadvantage", disadvantage.ToString()).Replace("DisFactor", trackBar4.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label54.Text = value.ToString();

            s = txtRatingLevelFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("petLevel", BattleBuddy.GetPetLevelPreCombat(2).ToString()).Replace("enemylevel", (cmbPetRatingPreviewLevel.SelectedIndex + 1).ToString()).Replace("LevelFactor", trackBar2.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label53.Text = value.ToString();

            label52.Text = total.ToString();

            //pet 3
            total = 0;
            disadvantage = 0;
            advantage = 0;

            s = txtRatingHealthFormula.Text;
            s = s.Replace("petHP", BattleBuddy.GetPetHPPreCombat(3).ToString()).Replace("HPFactor", trackBar1.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = int.Parse(value.ToString());
            label62.Text = value.ToString();

            mypet = BattleBuddy.GetTypeByID(BattleBuddy.ReadSlot(3));
            if (mypet == BattleBuddy.DumbChoiceTakeMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = -2;
            if (mypet == BattleBuddy.DumbChoiceDealLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) disadvantage = disadvantage - 1;//rating -1;
            if (mypet == BattleBuddy.SmartChoiceTakeLessDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = 1;
            if (mypet == BattleBuddy.SmartChoiceDealMoreDMG(cmbPetRatingPreviewSpecies.SelectedIndex + 1)) advantage = advantage + 2;
            s = txtRatingAdvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("advantage", advantage.ToString()).Replace("AdFactor", trackBar3.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label60.Text = value.ToString();

            s = txtRatingDisadvantageFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("disadvantage", disadvantage.ToString()).Replace("DisFactor", trackBar4.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label59.Text = value.ToString();

            s = txtRatingLevelFormula.Text;   //advantage * 50 * AdFactor
            s = s.Replace("petLevel", BattleBuddy.GetPetLevelPreCombat(3).ToString()).Replace("enemylevel", (cmbPetRatingPreviewLevel.SelectedIndex + 1).ToString()).Replace("LevelFactor", trackBar2.Value.ToString());

            value = BattleBuddy.Calculate(s);
            total = total + int.Parse(value.ToString());
            label58.Text = value.ToString();

            label57.Text = total.ToString();
        }



        private void loadpreviewimages()
        {
            //Logging.Write("loading image :" + ImgUrl(1));
            pictureBox6.ImageLocation = ImgUrl(1);

            //Logging.Write("loading image :" + ImgUrl(2));
            pictureBox7.ImageLocation = ImgUrl(2);

            //Logging.Write("loading image :" + ImgUrl(3));
            pictureBox8.ImageLocation = ImgUrl(3);
        }



        private string ImgUrl(int slotnum)
        {

            string theicon = BattleBuddy.SlotIcon(slotnum);
            string baseurl = "http://wow.zamimg.com/images/wow/icons/large/";
            string replace1 = @"INTERFACE\ICONS\";

            string image = theicon.Replace(replace1, "").Replace(".BLP", "").ToLower();
            image = baseurl + image + ".jpg";
            return image;
        }



        private string Img2Url(string ingamelocation)
        {

            string theicon = ingamelocation;
            string baseurl = "http://wow.zamimg.com/images/wow/icons/large/";
            string replace1 = @"INTERFACE\ICONS\";

            string image = theicon.Replace(replace1, "").Replace(".BLP", "").ToLower();
            image = baseurl + image + ".jpg";
            return image;
        }



        private void trackBar2_Scroll(object sender, System.EventArgs e)
        {
        }



        private void tbpagAdvancedSettings_Click(object sender, System.EventArgs e)
        {
        }



        private void btnAddAttackNeverItem_Click(object sender, System.EventArgs e)
        {
            lstNeverAttackItems.Items.Add(textBox7.Text);
        }



        private void btnAddAttackOnlyItem_Click(object sender, System.EventArgs e)
        {
            lstAttackOnlyItems.Items.Add(textBox7.Text);
        }



        private void btnRemoveAttackNeverItem_Click(object sender, System.EventArgs e)
        {
            if (lstNeverAttackItems.SelectedIndex > -1)
            {
                lstNeverAttackItems.Items.RemoveAt(lstNeverAttackItems.SelectedIndex);
            }
        }



        private void btnRemoveAttackOnlyItem_Click(object sender, System.EventArgs e)
        {
            if (lstAttackOnlyItems.SelectedIndex > -1)
            {
                lstAttackOnlyItems.Items.RemoveAt(lstAttackOnlyItems.SelectedIndex);
            }
        }



        private void btnLoadPreset_Click(object sender, System.EventArgs e)
        {
            LoadDefaults();
        }


        private void LoadDefaults()
        {
            lstDefaultLogic.Items.Clear();
            BattleBuddy.LoadDefaultLogic();
            string dumdum = BattleBuddy._DefaultLogicz.Logic;
            string[] PetLogics = dumdum.Split('@');
            foreach (string alogic in PetLogics)
            {
                lstDefaultLogic.Items.Add(alogic);
            }
        }



        private void btnRemoveLogicLine_Click(object sender, System.EventArgs e)
        {
            if (lstDefaultLogic.SelectedIndex > -1)
            {
                lstDefaultLogic.Items.RemoveAt(lstDefaultLogic.SelectedIndex);
            }
        }



        private void btnSavePreset_Click(object sender, System.EventArgs e)
        {
            SaveDefault();
        }


        private void SaveDefault()
        {
            int i = 0;
            string dummy = "";
            foreach (object item in lstDefaultLogic.Items)
            {
                dummy = dummy + item.ToString();
                if (i < lstDefaultLogic.Items.Count - 1) dummy = dummy + "@";
                i++;
            }
            BattleBuddy.LoadDefaultLogic();
            BattleBuddy._DefaultLogicz.Logic = dummy;
            BattleBuddy._DefaultLogicz.Save();
        }



        private void button21_Click(object sender, System.EventArgs e)
        {
            MoveItemPetRotate(-1);
            string order = "";
            foreach (object i in lbRotationOrder.Items)
            {
                if (order != "") order = order + "," + i.ToString();
                if (order == "") order = order + i.ToString();
            }
            BattleBuddy._MySettings.PetOrder = order;
        }



        private void button22_Click(object sender, System.EventArgs e)
        {
            MoveItemPetRotate(1);
            string order = "";
            foreach (object i in lbRotationOrder.Items)
            {
                if (order != "") order = order + "," + i.ToString();
                if (order == "") order = order + i.ToString();
            }
            BattleBuddy._MySettings.PetOrder = order;
        }



        private void cmbDoNotEngage_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.MinPetsAlive = cmbDoNotEngage.SelectedIndex + 1;
            BattleBuddy._MySettings.Save();
        }



        private void cmbUseBandages_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.UseBandagesToHeal = cmbUseBandages.SelectedIndex;
            BattleBuddy._MySettings.Save();
        }



        private void cmbUsePetHeal_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.UseHealSkill = cmbUsePetHeal.SelectedIndex;
            BattleBuddy._MySettings.Save();
        }



        private void textBox7_Enter(object sender, System.EventArgs e)
        {
        }



        private void txtRatingHealthFormula_TextChanged(object sender, System.EventArgs e)
        {
        }

        private void textBox7_TextChanged(object sender, System.EventArgs e)
        {
        }



        private void button28_Click(object sender, System.EventArgs e)
        {
            if (listBox1.SelectedIndex > -1)
            {
                lstDefaultLogic.Items.Add(listBox1.SelectedItem.ToString());
                listBox1.Items.Remove(listBox1.SelectedItem);
            }
        }



        private void label17_Click(object sender, System.EventArgs e)
        {
        }



        private void cbUseDenyList_CheckedChanged(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.UseBlackList = cbUseDenyList.Checked;
            BattleBuddy._MySettings.Save();
        }



        private void cbUseAllowList_CheckedChanged(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.UseWhiteList = cbUseAllowList.Checked;
            BattleBuddy._MySettings.Save();
        }



        private void btnLoadRatingPreset_Click(object sender, System.EventArgs e)
        {
            if (comboBox13.Text == "default leveling")
            {
                txtRatingHealthFormula.Text = "petHP * HPFactor";
                txtRatingAdvantageFormula.Text = "advantage * 50 * AdFactor";
                txtRatingDisadvantageFormula.Text = "disadvantage * 50 * DisFactor";
                txtRatingLevelFormula.Text = "(petLevel - enemylevel) * 4 * LevelFactor";

                trackBar1.Value = 8;
                trackBar2.Value = -50;
                trackBar3.Value = 4;
                trackBar4.Value = 4;
            }
        }



        private void trackBar1_Scroll(object sender, System.EventArgs e)
        {
        }



        private void trackBar3_Scroll(object sender, System.EventArgs e)
        {
        }



        private void trackBar4_Scroll(object sender, System.EventArgs e)
        {
        }



        private void SetBnB()
        {
            comboBox2.Enabled = false;
            comboBox3.Enabled = false;
            comboBox4.Enabled = false;
            button2.Enabled = false;
            button3.Enabled = false;
            button4.Enabled = false;

            if (comboBox11.SelectedIndex > -1)
            {
                comboBox2.Enabled = true;
            }
            if (comboBox2.Text != "")
            {
                comboBox3.Enabled = true;
                comboBox4.Enabled = true;
            }
            if (comboBox4.Text != "")
            {
                button3.Enabled = true;
                if (comboBox11.SelectedIndex > -1 && comboBox2.Text != "" && comboBox3.Text != "" && comboBox4.Text != "") button4.Enabled = true;
            }
            if (textBox2.Text != "") button2.Enabled = true;
        }



        private void pictureBox1_Click(object sender, System.EventArgs e)
        {
        }



        private void btnEditLogicLine_Click(object sender, System.EventArgs e)
        {
            if (lstDefaultLogic.SelectedIndex == -1) return;
            string value = lstDefaultLogic.SelectedItem.ToString();
            if (InputBox("Edit Logic", "Logic:", ref value) == DialogResult.OK)
            {
                int index = lstDefaultLogic.SelectedIndex;
                lstDefaultLogic.Items.RemoveAt(index);
                lstDefaultLogic.Items.Insert(index, value);
            }
        }



        private void button27_Click(object sender, System.EventArgs e)
        {
            if (listBox1.SelectedIndex == -1) return;
            string value = listBox1.SelectedItem.ToString();
            if (InputBox("Edit Logic", "Logic:", ref value) == DialogResult.OK)
            {
                int index = listBox1.SelectedIndex;
                listBox1.Items.RemoveAt(index);
                listBox1.Items.Insert(index, value);
            }
        }



        private void button31_Click(object sender, System.EventArgs e)
        {
            ClearBoxes();
            button46.Enabled = true;

            string theicon = "";
            if (numericUpDown1.Value == 0)
            {

                label75.Text = BattleBuddy.ReadSlot(comboBox17.SelectedIndex + 1);
                label77.Text = BattleBuddy.ReadSlotSpecies(comboBox17.SelectedIndex + 1);
                label71.Text = label75.Text;
                label22.Text = label77.Text;

                label79.Text = BattleBuddy.GetSpeciesByName(label77.Text);
                theicon = BattleBuddy.SlotIcon(comboBox17.SelectedIndex + 1);
            }
            else
            {
                int bla = (int)numericUpDown1.Value;
                //Logging.Write(bla.ToString());
                label75.Text = BattleBuddy.ReadIndex(bla);
                label77.Text = BattleBuddy.ReadIndexSpecies(bla);
                label79.Text = BattleBuddy.GetSpeciesByName(label77.Text);
                label71.Text = label75.Text;
                label22.Text = label77.Text;
                theicon = BattleBuddy.IndexIcon(bla);
            }


            string baseurl = "http://wow.zamimg.com/images/wow/icons/large/";
            string replace1 = @"INTERFACE\ICONS\";

            string image = theicon.Replace(replace1, "").Replace(".BLP", "").ToLower();
            image = baseurl + image + ".jpg";
            pictureBox10.ImageLocation = image;
            pictureBox2.ImageLocation = image;

            RefreshManager();
        }



        private void RefreshManager()
        {
            listView1.Items.Clear();
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;

            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();

                string stm = "SELECT * FROM Logics WHERE SpeciesID = " + label79.Text + "";

                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            string cel1 = rdr.GetInt32(0).ToString();
                            string[] row1 = { rdr.GetInt32(1).ToString(), rdr.GetString(2), rdr.GetInt32(3).ToString(), rdr.GetString(4), rdr.GetString(5), rdr.GetString(6), rdr.GetString(7), "?" };
                            listView1.Items.Add(cel1).SubItems.AddRange(row1);
                        }
                    }
                }
                bool haveadefault = false;
                foreach (ListViewItem dummy in listView1.Items)
                {
                    if (dummy.SubItems[3].Text == "1") haveadefault = true;
                }

                stm = "SELECT LogicID FROM PetSelection WHERE PetID = '" + label75.Text + "'";

                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            string cel1 = rdr.GetString(0);
                            foreach (ListViewItem dummy in listView1.Items)
                            {
                                if (dummy.SubItems[0].Text == cel1)
                                {
                                    dummy.SubItems[8].Text = "Yes";
                                }
                            }
                        }
                        if (!haveadefault && listView1.Items.Count > 0) label89.Visible = true; else label89.Visible = false;
                    }
                }
                con.Close();
            }
        }



        private void doNonQuery(string qq)
        {
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;

            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();

                using (SQLiteCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = qq;
                    cmd.ExecuteNonQuery();
                }
                con.Close();
            }

        }



        private bool CheckForDouble(string speciesid, string logic, string spellset)
        {
            string qq = "SELECT * FROM Logics WHERE SpeciesID = " + speciesid + " and Logic = '" + logic + "' and Spellset = '" + spellset + "'";
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;

            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();

                using (SQLiteCommand cmd = new SQLiteCommand(qq, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            return true;
                        }
                    }
                }
                con.Close();
            }
            return false;
        }



        private void button32_Click(object sender, System.EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                string q = @"UPDATE Logics 
            SET isDefault = 1 Where ID = " + listView1.SelectedItems[0].Text + "";
                doNonQuery(q);
                q = @"UPDATE Logics 
            SET isDefault = 0 Where SpeciesID = '" + label79.Text + "' AND ID <> " + listView1.SelectedItems[0].Text + "";
                doNonQuery(q);
                RefreshManager();
            }
        }


        static bool DigitsOnly(string s)
        {
            foreach (char c in s)
            {
                if (c < '0' || c > '9')
                    return false;
            }
            return true;
        }



        private string LogicRecNum(string speciesid, string logic, string spellset)
        {
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;

            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();
                string stm = "SELECT ID FROM Logics WHERE SpeciesID = " + speciesid + " and Logic = '" + logic + "' and Spellset = '" + spellset + "'";
                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            string cel1 = rdr.GetInt32(0).ToString();
                            return cel1;
                        }
                    }
                }
                con.Close();
            }
            return "error";
        }



        private string getLogic(string logicid)
        {
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;

            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();

                string stm = "SELECT Logic FROM Logics WHERE ID = " + logicid;

                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            string cel1 = rdr.GetString(0);
                            return cel1;
                        }
                    }
                }
                con.Close();

            }
            return "error";
        }



        private string getNote(string logicid)
        {
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;
            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();
                string stm = "SELECT Notes FROM Logics WHERE ID = " + logicid;
                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            string cel1 = rdr.GetString(0);
                            return cel1;
                        }
                    }
                }
                con.Close();
            }
            return "error";
        }



        private string getSpellset(string logicid)
        {
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;
            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();
                string stm = "SELECT Spellset FROM Logics WHERE ID = " + logicid;
                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            string cel1 = rdr.GetString(0);
                            return cel1;
                        }
                    }
                }
                con.Close();
            }
            return "error";
        }


        private string getAuthor(string logicid)
        {
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;

            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();
                string stm = "SELECT Author FROM Logics WHERE ID = " + logicid;
                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            string cel1 = rdr.GetString(0);
                            return cel1;
                        }
                    }
                }
                con.Close();
            }
            return "error";
        }



        private void SetPetLogic(string petid, string logicid)
        {
            string cs = "URI=file:" + BattleBuddy._PetLogicsDbPath;
            string cel1 = "";
            using (SQLiteConnection con = new SQLiteConnection(cs))
            {
                con.Open();
                if (logicid == "-1")
                {
                    string q = @"DELETE FROM PetSelection Where PetID = " + petid;
                    doNonQuery(q);
                    return;
                }

                string stm = "SELECT LogicID FROM PetSelection WHERE PetID = " + petid;

                using (SQLiteCommand cmd = new SQLiteCommand(stm, con))
                {
                    using (SQLiteDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            cel1 = rdr.GetString(0);

                        }
                    }
                }
                con.Close();

            }
            if (cel1 == "")
            {
                string q = "INSERT INTO PetSelection(PetID,LogicID) VALUES('" + petid + "','" + logicid + "')";
                doNonQuery(q);
            }
            else
            {
                string q = @"UPDATE PetSelection 
            SET LogicID = '" + logicid + @"',
            Where PetID = '" + petid + "'";
                doNonQuery(q);
            }
        }



        private void ImportFile(string filename)
        {
            BattleBuddy.LoadPetbyFile(filename);

            if (DigitsOnly(Path.GetFileName(filename).Replace(".xml", "")))
            {

                string PetID = Path.GetFileName(filename).Replace(".xml", "");
                string Logic = BattleBuddy._PetSettings.Logic;
                string SpellSet = BattleBuddy._PetSettings.SpellLayout;
                string isDefault = "0";
                string Author = "Unknown";
                string Note = "No note yet";
                string LogicType = "0";
                //MessageBox.Show("" + PetID);
                string SpeciesID = BattleBuddy.GetSpeciesIDByID(PetID);
                if (SpeciesID == "Error")
                {
                    Logging.Write("Error, could not recognize " + Path.GetFileName(filename));
                    return;
                }

                //check voor dubbele (species, logic & spellset)
                if (!CheckForDouble(SpeciesID, Logic, SpellSet))
                {
                    //geen dubbele? Insert it!

                    string q = "INSERT INTO Logics(SpeciesID,LogicType,isDefault,Author,Logic,Spellset,Notes) VALUES(" + SpeciesID + ",'" + LogicType + "'," + isDefault + ",'" + Author + "','" + Logic + "','" + SpellSet + "','" + Note + "')";
                    doNonQuery(q);
                    //Set Pet Selected Logic
                    SetPetLogic(PetID, LogicRecNum(SpeciesID, Logic, SpellSet));
                }
            }
            else
            {
                string Logic = BattleBuddy._PetSettings.Logic;
                string SpellSet = BattleBuddy._PetSettings.SpellLayout;
                string isDefault = "1";
                string Author = "Unknown";
                string Note = "No note yet";
                string LogicType = "0";
                string SpeciesID = BattleBuddy.GetSpeciesByName(Path.GetFileName(filename).Replace(".xml", ""));
                if (!CheckForDouble(SpeciesID, Logic, SpellSet))
                {
                    string q = "INSERT INTO Logics(SpeciesID,LogicType,isDefault,Author,Logic,Spellset,Notes) VALUES(" + SpeciesID + ",'" + LogicType + "'," + isDefault + ",'" + Author + "','" + Logic + "','" + SpellSet + "','" + Note + "')";
                    doNonQuery(q);
                }

            }
        }



        private void button33_Click(object sender, System.EventArgs e)
        {
            openFileDialog1.InitialDirectory = BattleBuddy._PetSettingsPath;
            DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
            if (result == DialogResult.OK) // Test result.
            {
                string file = openFileDialog1.FileName;

                try
                {
                    ImportFile(file);
                }
                catch (IOException exc)
                {
                    BBLog.LogException(exc);
                }
            }
        }



        private void button35_Click(object sender, System.EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                MessageBox.Show(getLogic(listView1.SelectedItems[0].Text));
            }
        }



        private void button34_Click(object sender, System.EventArgs e)
        {
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                //
                // The user selected a folder and pressed the OK button.
                // We print the number of files found.
                //
                var files = Directory.GetFiles(folderBrowserDialog1.SelectedPath).Where(s => s.ToLower().EndsWith(".xml")); ;
                //                MessageBox.Show("Files found: " + files.Count(), "Message");
                foreach (string s in files)
                {
                    ImportFile(s);
                }
            }
        }



        private void UpdateViewBoxes()
        {
            textBox10.Text = getNote(listView1.SelectedItems[0].Text);
            textBox11.Text = listView1.SelectedItems[0].SubItems[2].Text;
            textBox8.Text = getLogic(listView1.SelectedItems[0].Text);
            textBox9.Text = getSpellset(listView1.SelectedItems[0].Text);
            label84.Text = getAuthor(listView1.SelectedItems[0].Text);
            button40.Enabled = true;
            button41.Enabled = (label84.Text == "Unknown");
            button32.Enabled = true;
            button42.Enabled = true;
            button43.Enabled = false;
            button39.Enabled = true;
            button47.Enabled = true;
            button53.Enabled = true;
            button38.Enabled = true;
            button56.Enabled = true;
            button36.Enabled = true;
            button37.Enabled = true;
            button49.Enabled = true;
            button61.Enabled = true;
        }



        private void ClearBoxes()
        {
            textBox11.Text = "";
            groupBox10.Visible = false;
            button32.Enabled = false;
            textBox10.Text = "";
            textBox8.Text = "";
            textBox9.Text = "";
            label84.Text = "";
            button40.Enabled = false;
            button42.Enabled = false;
            button41.Enabled = false;
            button43.Enabled = false;
            button39.Enabled = false;
            button47.Enabled = false;
            button38.Enabled = false;
            button53.Enabled = false;
            button56.Enabled = false;
            button36.Enabled = false;
            button37.Enabled = false;
            button49.Enabled = false;
            button61.Enabled = false;
        }



        private void button40_Click(object sender, System.EventArgs e)
        {
            string defaultval = getNote(listView1.SelectedItems[0].Text);
            if (InputBox("Edit Note", "Note:", ref defaultval) == DialogResult.OK)
            {
                textBox10.Text = defaultval;
            }
            button43.Enabled = true;
        }



        private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                ClearBoxes();

            }
            else UpdateViewBoxes();
        }



        private void tbpagLogicManager_Click(object sender, System.EventArgs e)
        {

        }



        private void button42_Click(object sender, System.EventArgs e)
        {
            //button43.Enabled = true;
            for (int i = 0; i < 99; i++)
            {
                if (i < listView2.Items.Count) listView2.Items[i].Checked = false;
                if (textBox11.Text.Contains(i.ToString()) && i < listView2.Items.Count) listView2.Items[i].Checked = true;
            }
            groupBox16.Visible = true;
        }

        private void button43_Click(object sender, System.EventArgs e)
        {
            string q = @"UPDATE Logics 
            SET Notes = '" + textBox10.Text + @"',
            Logic = '" + textBox8.Text + @"',
            Author = '" + label84.Text + @"',
            Spellset = '" + textBox9.Text + @"',
            LogicType = '" + textBox11.Text + @"'
            
            Where ID = " + listView1.SelectedItems[0].Text;
            //Logging.Write("Query : " + q);
            doNonQuery(q);
            //LogicType = " + textBox11.Text + @",
            RefreshManager();
            ClearBoxes();
        }



        private void button41_Click(object sender, System.EventArgs e)
        {
        }



        private void button39_Click(object sender, System.EventArgs e)
        {
            SpellBoxUpdater();
            groupBox10.Visible = true;
        }



        public void SpellBoxUpdater()
        {
            //read spells
            List<string> skillids = Lua.GetReturnValues("idTable, levelTable = C_PetJournal.GetPetAbilityList(" + label79.Text + ") return idTable[1],idTable[2],idTable[3],idTable[4],idTable[5],idTable[6];");

            string[] iconz = { PetSpellIcon(skillids[0]), PetSpellIcon(skillids[1]), PetSpellIcon(skillids[2]), PetSpellIcon(skillids[3]), PetSpellIcon(skillids[4]), PetSpellIcon(skillids[5]) };

            //set spell names
            //146235
            radioButton1.Text = PetSpellName(skillids[0]);
            radioButton4.Text = PetSpellName(skillids[1]);
            radioButton6.Text = PetSpellName(skillids[2]);
            radioButton2.Text = PetSpellName(skillids[3]);
            radioButton3.Text = PetSpellName(skillids[4]);
            radioButton5.Text = PetSpellName(skillids[5]);

            radioButton1.Tag = skillids[0];
            radioButton4.Tag = skillids[1];
            radioButton6.Tag = skillids[2];
            radioButton2.Tag = skillids[3];
            radioButton3.Tag = skillids[4];
            radioButton5.Tag = skillids[5];

            string dummy = "";  //9 13 15  11 12 14

            dummy = PetSpellDesc(skillids[0]);
            toolTip1.SetToolTip(this.radioButton1, dummy);
            toolTip1.SetToolTip(this.pictureBox9, dummy);

            dummy = PetSpellDesc(skillids[1]);
            toolTip1.SetToolTip(this.radioButton2, dummy);
            toolTip1.SetToolTip(this.pictureBox13, dummy);

            dummy = PetSpellDesc(skillids[2]);
            toolTip1.SetToolTip(this.radioButton4, dummy);
            toolTip1.SetToolTip(this.pictureBox15, dummy);

            dummy = PetSpellDesc(skillids[3]);
            toolTip1.SetToolTip(this.radioButton3, dummy);
            toolTip1.SetToolTip(this.pictureBox11, dummy);

            dummy = PetSpellDesc(skillids[4]);
            toolTip1.SetToolTip(this.radioButton6, dummy);
            toolTip1.SetToolTip(this.pictureBox12, dummy);

            dummy = PetSpellDesc(skillids[5]);
            toolTip1.SetToolTip(this.radioButton5, dummy);
            toolTip1.SetToolTip(this.pictureBox14, dummy);

            SetSpellIcons(iconz);

            //set currently equipped in logic
            List<string> skillzequipped = new List<string> { "0", "0", "0" };

            if (textBox9.Text.Contains("(0)") || textBox9.Text == "")
            {
                skillzequipped = Lua.GetReturnValues("for i=1,3 do local petID, ability1ID, ability2ID, ability3ID, locked = C_PetJournal.GetPetLoadOutInfo(i) if (tonumber(petID,16)==" + label75.Text + ") then return ability1ID, ability2ID, ability3ID end end return 0,0,0");
            }
            else
            {
                string dumdum = textBox9.Text;

                string[] PetLogics = dumdum.Split('@');

                foreach (string alogic in PetLogics)
                {
                    if ((String.Compare(alogic.Substring(0, 15), "ASSIGNABILITY1(") == 0))
                    {
                        int FirstChr = alogic.IndexOf("ASSIGNABILITY1(") + 15;
                        int SecondChr = alogic.IndexOf(")", FirstChr);
                        string strTemp = alogic.Substring(FirstChr, SecondChr - FirstChr);

                        skillzequipped[0] = strTemp;
                    }
                    if ((String.Compare(alogic.Substring(0, 15), "ASSIGNABILITY2(") == 0))
                    {
                        int FirstChr = alogic.IndexOf("ASSIGNABILITY2(") + 15;
                        int SecondChr = alogic.IndexOf(")", FirstChr);
                        string strTemp = alogic.Substring(FirstChr, SecondChr - FirstChr);

                        skillzequipped[1] = strTemp;
                    }
                    if ((String.Compare(alogic.Substring(0, 15), "ASSIGNABILITY3(") == 0))
                    {
                        int FirstChr = alogic.IndexOf("ASSIGNABILITY3(") + 15;
                        int SecondChr = alogic.IndexOf(")", FirstChr);
                        string strTemp = alogic.Substring(FirstChr, SecondChr - FirstChr);

                        skillzequipped[2] = strTemp;
                    }
                }


            }

            foreach (string s in skillzequipped)
            {
                if (radioButton1.Text == PetSpellName(s)) radioButton1.Checked = true;
                if (radioButton2.Text == PetSpellName(s)) radioButton2.Checked = true;
                if (radioButton3.Text == PetSpellName(s)) radioButton3.Checked = true;
                if (radioButton4.Text == PetSpellName(s)) radioButton4.Checked = true;
                if (radioButton5.Text == PetSpellName(s)) radioButton5.Checked = true;
                if (radioButton6.Text == PetSpellName(s)) radioButton6.Checked = true;
            }
        }



        private void SetSpellIcons(string[] icons)
        {
            //9 13 15  11 12 14
            pictureBox9.ImageLocation = Img2Url(icons[0]);
            pictureBox13.ImageLocation = Img2Url(icons[1]);
            pictureBox15.ImageLocation = Img2Url(icons[2]);
            pictureBox11.ImageLocation = Img2Url(icons[3]);
            pictureBox12.ImageLocation = Img2Url(icons[4]);
            pictureBox14.ImageLocation = Img2Url(icons[5]);
        }



        private string PetSpellName(string SpellID)
        {
            string luastring = "_, name, icon,_,_,_,_,_ = C_PetBattles.GetAbilityInfoByID(" + SpellID + ") return name"; //,icon)
            List<string> cnt = Lua.GetReturnValues(luastring);
            try
            {
                return cnt[0];
            }
            catch (Exception exc) { BBLog.LogException(exc); }
            return "error";
        }



        private string PetSpellDesc(string SpellID)
        {
            string luastring = "_, name, icon,_,desc,_,_,_ = C_PetBattles.GetAbilityInfoByID(" + SpellID + ") return desc"; //,icon)
            List<string> cnt = Lua.GetReturnValues(luastring);
            try
            {
                return cnt[0];
            }
            catch (Exception exc) {
                BBLog.LogException(exc);
            }
            return "error";
        }



        //id, name, icon, maxCooldown, unparsedDescription, numTurns, petType, noStrongWeakHints = C_PetBattles.GetAbilityInfoByID(abilityID)
        private string PetSpellIcon(string SpellID)
        {
            string luastring = "_, name, icon,_,_,_,_,_ = C_PetBattles.GetAbilityInfoByID(" + SpellID + ") return icon"; //,icon)
            List<string> cnt = Lua.GetReturnValues(luastring);
            try
            {
                return cnt[0];
            }
            catch (Exception exc) { BBLog.LogException(exc); }
            return "error";
        }



        private void button45_Click_1(object sender, System.EventArgs e)
        {
            groupBox10.Visible = false;
        }



        private void button44_Click_1(object sender, System.EventArgs e)
        {
            //12 43  65
            string[] cnt1 = { "", "", "" };
            if (radioButton1.Checked) { cnt1[0] = radioButton1.Tag.ToString(); } else { cnt1[0] = radioButton2.Tag.ToString(); }
            if (radioButton3.Checked) { cnt1[1] = radioButton3.Tag.ToString(); } else { cnt1[1] = radioButton4.Tag.ToString(); }
            if (radioButton5.Checked) { cnt1[2] = radioButton5.Tag.ToString(); } else { cnt1[2] = radioButton6.Tag.ToString(); }
            string spelllayout = "ASSIGNABILITY1(" + cnt1[0] + ")@" +
                                    "ASSIGNABILITY2(" + cnt1[1] + ")@" +
                                    "ASSIGNABILITY3(" + cnt1[2] + ")";
            textBox9.Text = spelllayout;
            button43.Enabled = true;
            groupBox10.Visible = false;
        }



        private void button36_Click(object sender, System.EventArgs e)
        {
            //77 79

            string exportstring = "[code]";
            exportstring = exportstring + "[Name]" + label77.Text + @"[/Name]" + Environment.NewLine;
            exportstring = exportstring + "[Species]" + label79.Text + @"[/Species]" + Environment.NewLine;
            exportstring = exportstring + "[Logic]" + textBox8.Text + @"[/Logic]" + Environment.NewLine;
            exportstring = exportstring + "[Spells]" + textBox9.Text + @"[/Spells]" + Environment.NewLine;
            exportstring = exportstring + "[Author]" + label84.Text + @"[/Author]" + Environment.NewLine;
            exportstring = exportstring + "[Notes]" + textBox10.Text + @"[/Notes]" + Environment.NewLine;
            exportstring = exportstring + "[LogicType]" + textBox11.Text + @"[/LogicType]";
            exportstring = exportstring + "[/code]";
            DialogResult bla = InputBox("Export", "Copy & Paste this to the forum :", ref exportstring);
        }



        private void button37_Click(object sender, System.EventArgs e)
        {
            string value = "";
            if (MultiInputBox("Import from Forum", "Paste here :", ref value) == DialogResult.OK)
            {
                button43.Enabled = true;
                if (value.IndexOf("[Logic]") > -1)
                {
                    int FirstChr = value.IndexOf("[Logic]") + "[Logic]".Length;
                    int SecondChr = value.IndexOf("[/Logic]", FirstChr);
                    textBox8.Text = value.Substring(FirstChr, SecondChr - FirstChr);
                    //BBLog(dumdumdum+" "+FirstChr+" "+SecondChr+""+CheckForBuff(dumdumdum));

                }
                if (value.IndexOf("[Name]") > -1)
                {
                    int FirstChr = value.IndexOf("[Name]") + "[Name]".Length;
                    int SecondChr = value.IndexOf("[/Name]", FirstChr);
                    if (value.Substring(FirstChr, SecondChr - FirstChr) != label77.Text) MessageBox.Show("Name does not match!");
                    //BBLog(dumdumdum+" "+FirstChr+" "+SecondChr+""+CheckForBuff(dumdumdum));

                }
                if (value.IndexOf("[Species]") > -1)
                {
                    int FirstChr = value.IndexOf("[Species]") + "[Species]".Length;
                    int SecondChr = value.IndexOf("[/Species]", FirstChr);
                    if (value.Substring(FirstChr, SecondChr - FirstChr) != label77.Text) MessageBox.Show("Species does not match!");
                    //BBLog(dumdumdum+" "+FirstChr+" "+SecondChr+""+CheckForBuff(dumdumdum));

                }
                if (value.IndexOf("[Spells]") > -1)
                {
                    int FirstChr = value.IndexOf("[Spells]") + "[Spells]".Length;
                    int SecondChr = value.IndexOf("[/Spells]", FirstChr);
                    textBox9.Text = value.Substring(FirstChr, SecondChr - FirstChr);
                    //BBLog(dumdumdum+" "+FirstChr+" "+SecondChr+""+CheckForBuff(dumdumdum));

                }
                if (value.IndexOf("[Author]") > -1)
                {
                    int FirstChr = value.IndexOf("[Author]") + "[Author]".Length;
                    int SecondChr = value.IndexOf("[/Author]", FirstChr);
                    label84.Text = value.Substring(FirstChr, SecondChr - FirstChr);
                    //BBLog(dumdumdum+" "+FirstChr+" "+SecondChr+""+CheckForBuff(dumdumdum));

                }
                if (value.IndexOf("[Notes]") > -1)
                {
                    int FirstChr = value.IndexOf("[Notes]") + "[Notes]".Length;
                    int SecondChr = value.IndexOf("[/Notes]", FirstChr);
                    textBox10.Text = value.Substring(FirstChr, SecondChr - FirstChr);
                    //BBLog(dumdumdum+" "+FirstChr+" "+SecondChr+""+CheckForBuff(dumdumdum));

                }
                if (value.IndexOf("[LogicType]") > -1)
                {
                    int FirstChr = value.IndexOf("[LogicType]") + "[LogicType]".Length;
                    int SecondChr = value.IndexOf("[/LogicType]", FirstChr);
                    textBox11.Text = value.Substring(FirstChr, SecondChr - FirstChr);
                    //BBLog(dumdumdum+" "+FirstChr+" "+SecondChr+""+CheckForBuff(dumdumdum));
                }
            }
        }



        private void checkBox8_CheckedChanged(object sender, System.EventArgs e)
        {
            //if (checkBox8.Checked) checkBox3.Checked = true;
            BattleBuddy._MySettings.DoPreCombatSwapping = cbPrecombatSwapping.Checked;
            BattleBuddy._MySettings.Save();
        }



        private void cbUseAdvanceRatingSystem_CheckedChanged_1(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.UseRatingSystem = cbUseAdvancedRatingSystem.Checked;
            BattleBuddy._MySettings.Save();
        }



        private void button47_Click(object sender, System.EventArgs e)
        {
            string q = @"DELETE FROM Logics Where ID = " + listView1.SelectedItems[0].Text;
            //Logging.Write("Query : " + q);
            doNonQuery(q);
            //LogicType = " + textBox11.Text + @",
            RefreshManager();
            ClearBoxes();
        }

        private void button46_Click(object sender, System.EventArgs e)
        {
            string q = @"INSERT INTO Logics 
            (SpeciesID, Notes, Logic, Author, Spellset, Logictype) VALUES(
            " + label79.Text + @",
            'New',
            'SWAPOUT Health(THISPET) ISLESSTHAN 30@CASTSPELL(1) COOLDOWN(SKILL(1)) EQUALS false',
            'Unknown',
            'ASSIGNABILITY1(0)@ASSIGNABILITY2(0)@ASSIGNABILITY3(0)',
            '0')";
            //Logging.Write("Query : " + q);
            doNonQuery(q);
            //LogicType = " + textBox11.Text + @",
            RefreshManager();
            ClearBoxes();
        }



        private void hiddenbox_TextChanged(object sender, System.EventArgs e)
        {
            //een zooi buttons enablen/disablen
            if (hiddenbox.Text != "")
            {
                button48.Enabled = true;
                button48.Visible = true;
            }
            else
            {
                button48.Enabled = false;
                button48.Visible = false;
            }
        }



        private void button48_Click(object sender, System.EventArgs e)
        {
            string dummy = "";

            int i = 0;
            foreach (object item in listBox1.Items)
            {
                dummy = dummy + item.ToString();
                if (i < listBox1.Items.Count - 1) dummy = dummy + "@";
                i++;
            }
            textBox8.Text = dummy;
            button43.Enabled = true;
            button48.Visible = false;
            hiddenbox.Text = "";
        }



        private void button38_Click(object sender, System.EventArgs e)
        {

            hiddenbox.Text = textBox8.Text;


            string dumdum = hiddenbox.Text;
            string[] PetLogics = dumdum.Split('@');
            listBox1.Items.Clear();
            foreach (string alogic in PetLogics)
            {
                AddToList(alogic);
            }
        }

        private void SetBotBase(string tofind)
        {
            if (BotManager.Current.Name.Contains(tofind)) return;
            if (TreeRoot.IsRunning)
            {
                TreeRoot.Stop();
                StyxWoW.Sleep(1000);
            }
            foreach (KeyValuePair<string, BotBase> Base in BotManager.Instance.Bots)
            {
                if (Base.Key.ToLower().Contains(tofind))
                {
                    BotManager.Instance.SetCurrent(Base.Value);
                    if (!BotManager.Current.Initialized) BotManager.Current.Initialize();
                    StyxWoW.Sleep(500);
                }
            }
            ProfileManager.LoadEmpty();
            StyxWoW.Sleep(500);
            TreeRoot.Start();
            //Logging.Write("Correct botbase selected");
        }
        private void EnablePlugin(string plugname)
        {
            Styx.Plugins.PluginContainer MyPlugin = Styx.Plugins.PluginManager.Plugins.FirstOrDefault(p => p.Plugin.Name == plugname);
            if (MyPlugin != null) MyPlugin.Enabled = true;

        }

        private void GetQuickSettings()
        {
            string[] array = Directory.GetFiles(BattleBuddy._QuickSettingsPath, "*.cs");
            //Logging.Write("getting quicksettings" + array.Length.ToString());
            foreach (string s in array.Where(pp => !pp.Contains("blank")))
            {
                //  Logging.Write(s);
                string ddd = Path.GetFileName(s).Replace(".cs", "") + "Init";
                //Logging.Write(ddd);


                MethodInfo theMethod = this.GetType().GetMethod(ddd);

                try
                {
                    if (BattleBuddy._QuickSettingsNames.Count < array.Length - 1) theMethod.Invoke(this, null);
                }
                catch (Exception exc)
                {
                    BBLog.LogException(exc);
                }

            }
            lbOneClickSettings.Items.Clear();
            foreach (string s in BattleBuddy._QuickSettingsNames)
            {
                lbOneClickSettings.Items.Add(s);
            }

        }

        private void closeForm()
        {
            BlacklistSave();
            WhitelistSave();
            BattleBuddy._MySettings.HPFormula = txtRatingHealthFormula.Text;
            BattleBuddy._MySettings.AdFormula = txtRatingAdvantageFormula.Text;
            BattleBuddy._MySettings.DisFormula = txtRatingDisadvantageFormula.Text;
            BattleBuddy._MySettings.LevelFormula = txtRatingLevelFormula.Text;


            BattleBuddy._MySettings.Save();
            this.Close();
        }


        private void cbAutoUpdate_CheckedChanged(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.AllowAutoUpdate = cbAutoUpdate.Checked;
            BattleBuddy._MySettings.Save();
        }

        private void btnUpdateNow_Click(object sender, System.EventArgs e)
        {
            Updater.CheckForUpdate(BattleBuddy._BattleBuddyPath, false);
        }

        private void button55_Click(object sender, System.EventArgs e)
        {
            List<string> cnt = Lua.GetReturnValues("totalpets,_=C_PetJournal.GetNumPets() return totalpets");
            StringBuilder sb = new StringBuilder();
            Logging.Write(cnt[0]);
            for (int i = 1; i <= int.Parse(cnt[0]); i++)
            {
                List<string> cnt2 = Lua.GetReturnValues("local dummy1='' _,species,_,_,_,_,_,name,url=C_PetJournal.GetPetInfoByIndex(" + i.ToString() + ") dummy1 = dummy1 .. '*1*' .. species .. '*2*' .. name ..'*3*'.. url ..'*4*\\r\\n' return dummy1");

                Logging.Write(cnt2[0]);

                if (!sb.ToString().Contains(cnt2[0])) sb.Append(cnt2[0]);
            }

            using (StreamWriter outfile = new StreamWriter(@"c:\AllPetData.txt"))
            {
                outfile.Write(sb.ToString());
            }

        }

        private void button56_Click(object sender, System.EventArgs e)
        {
            SetPetLogic(label75.Text, listView1.SelectedItems[0].Text);
        }

        private void comboBox17_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            numericUpDown1.Value = 0;

        }

        private void numericUpDown1_ValueChanged(object sender, System.EventArgs e)
        {
            comboBox17.SelectedText = "";
        }

        private void button58_Click(object sender, System.EventArgs e)
        {
            groupBox16.Visible = false;
        }

        private void button57_Click(object sender, System.EventArgs e)
        {
            string dummy = "";
            foreach (ListViewItem l in listView2.Items)
            {
                if (l.Checked) dummy = dummy + l.Index.ToString() + " ";
            }
            textBox11.Text = dummy;
            groupBox16.Visible = false;
            button43.Enabled = true;
        }

        private void cbAllowRoleDetection_CheckedChanged(object sender, System.EventArgs e)
        {
            BattleBuddy._MySettings.AllowRoleDetect = cbDetailedLogging.Checked;
            BattleBuddy._MySettings.Save();
        }

        private void listBox8_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (lbOneClickSettings.SelectedIndex < 0) return;
            txtOneClickDescription.Text = BattleBuddy._QuickSettingsDescriptions[lbOneClickSettings.SelectedIndex];
        }

        private void button59_Click(object sender, System.EventArgs e)
        {
            if (lbOneClickSettings.SelectedIndex < 0) return;
            string ddd = BattleBuddy._QuickSettingsFunctions[lbOneClickSettings.SelectedIndex];
            MethodInfo theMethod = this.GetType().GetMethod(ddd);

            try
            {
                theMethod.Invoke(this, null);
            }
            catch (Exception exc)
            {
                BBLog.LogException(exc);
            }
        }

        private void button49_Click(object sender, System.EventArgs e)
        {
            SetPetLogic(label75.Text, "-1");
        }

        private void btnBattlePetSwapperSettings_Click(object sender, System.EventArgs e)
        {
            //BattleBuddy.BPS.OnButtonPress();

        }


        
        private void button51_Click(object sender, System.EventArgs e)
        {
            Librarian.Librarian Lib = new Librarian.Librarian();
            Lib.Show();
        }


        private void button52_Click(object sender, System.EventArgs e)
        {
            string[] skillz = textBox9.Text.Split('@');
            string[] gotskills = { "", "", "" };

            foreach (string alogic in skillz)
            {
                if ((String.Compare(alogic.Substring(0, 15), "ASSIGNABILITY1(") == 0))
                {
                    int FirstChr = alogic.IndexOf("ASSIGNABILITY1(") + 15;
                    int SecondChr = alogic.IndexOf(")", FirstChr);
                    string strTemp = alogic.Substring(FirstChr, SecondChr - FirstChr);

                    gotskills[0] = strTemp;
                }
                if ((String.Compare(alogic.Substring(0, 15), "ASSIGNABILITY2(") == 0))
                {
                    int FirstChr = alogic.IndexOf("ASSIGNABILITY2(") + 15;
                    int SecondChr = alogic.IndexOf(")", FirstChr);
                    string strTemp = alogic.Substring(FirstChr, SecondChr - FirstChr);

                    gotskills[1] = strTemp;
                }
                if ((String.Compare(alogic.Substring(0, 15), "ASSIGNABILITY3(") == 0))
                {
                    int FirstChr = alogic.IndexOf("ASSIGNABILITY3(") + 15;
                    int SecondChr = alogic.IndexOf(")", FirstChr);
                    string strTemp = alogic.Substring(FirstChr, SecondChr - FirstChr);

                    gotskills[2] = strTemp;
                }
            }


            if (comboBox18.Text == "1")
            {
                Librarian.Librarian libje = new Librarian.Librarian();
                string dummy = libje.SearchLib(gotskills[0]);

                AddToList(dummy.Replace("**sn**", "1"));
            }
            if (comboBox18.Text == "2")
            {
                Librarian.Librarian libje = new Librarian.Librarian();
                string dummy = libje.SearchLib(gotskills[1]);

                AddToList(dummy.Replace("**sn**", "2"));
            }
            if (comboBox18.Text == "3")
            {
                Librarian.Librarian libje = new Librarian.Librarian();
                string dummy = libje.SearchLib(gotskills[2]);

                AddToList(dummy.Replace("**sn**", "3"));
            }

        }

        private void dataGridView1_CellClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {

        }

        private void button53_Click(object sender, System.EventArgs e)
        {
            if (textBox9.Text.Contains("(0)"))
            {
                MessageBox.Show("Please select skills first");
                return;
            }

            Librarian.Librarian lib = new Librarian.Librarian();
            textBox8.Text = lib.GenerateLogic(textBox9.Text).Replace("@@", "@").Replace("@@", "@");
            textBox10.Text = "Auto generated";
        }

        private void button61_Click(object sender, System.EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0) {
                string q = @"UPDATE Logics 
            SET isDefault = 0 Where SpeciesID = '" + label79.Text + "'";
                doNonQuery(q);
                RefreshManager();
                /*ListViewItem itm = ;
                textBox1.Text = itm.SubItems[0].Text;
                textBox2.Text = itm.SubItems[1].Text;*/
            }
        }

        private void tabPage5_Click(object sender, System.EventArgs e)
        {
        }

        private void cmbMode_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
    }
}



namespace BattleBuddyplug
{
    public partial class configForm : Form
    {
        string[] options = { 
            "COOLDOWN(SKILL(1))","EQUALS", "true,false",
            "COOLDOWN(SKILL(2))","EQUALS", "true,false", 
            "COOLDOWN(SKILL(3))","EQUALS", "true,false", 
            "Health(THISPET)","EQUALS,ISLESSTHAN,ISGREATERTHAN", "NUMBER,Health(ENEMYPET)", 
            "Health(ENEMYPET)","EQUALS,ISLESSTHAN,ISGREATERTHAN", "NUMBER,Health(THISPET)", 
            "MyPetLevel","EQUALS,ISLESSTHAN,ISGREATERTHAN", "NUMBER,EnemyPetLevel,EnemyPetLevel + NUMBER", 
            "EnemyPetLevel","EQUALS,ISLESSTHAN,ISGREATERTHAN", "NUMBER,MyPetLevel,MyPetLevel + NUMBER", 
            "ENEMYTYPE","EQUALS,ISNOT", "HUMANOID,DRAGONKIN,FLYING,UNDEAD,CRITTER,MAGIC,ELEMENTAL,BEAST,AQUATIC,MECHANICAL", 
            "HASBUFF(X)","EQUALS", "true,false", 
            "HASENEMYBUFF(X)","EQUALS","true,false",  
            "WEATHERBUFF(X)","EQUALS", "true,false", 
            "HASTEAMBUFF(X)","EQUALS", "true,false", 
            "ENEMYTEAMBUFF(X)","EQUALS","true,false", 
            "MYPETSPEED","EQUALS,ISLESSTHAN,ISGREATERTHAN","NUMBER,ENEMYSPEED", 
            "ENEMYSPEED","EQUALS,ISLESSTHAN,ISGREATERTHAN","NUMBER,MYPETSPEED",
            "MyPetsAlive","EQUALS,ISLESSTHAN,ISGREATERTHAN","NUMBER,EnemyPetsAlive",
            "EnemyPetsAlive","EQUALS,ISLESSTHAN,ISGREATERTHAN","NUMBER,MyPetsAlive"
        };

        public configForm()
        {
            InitializeComponent();
        }

        private void TheDungeonComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
        }


        private void cmbCapture_SelectedIndexChanged(object sender, EventArgs e)
        {
            BattleBuddy._MySettings.GetRarity = cmbCapture.SelectedIndex + 1;
            BattleBuddy._MySettings.Save();
        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            label1.Text = trackBar1.Value.ToString();
            BattleBuddy._MySettings.HPFactor = trackBar1.Value;
            BattleBuddy._MySettings.Save();
        }


        private void trackBar2_ValueChanged(object sender, EventArgs e)
        {
            label2.Text = trackBar2.Value.ToString();
            BattleBuddy._MySettings.LevelFactor = trackBar2.Value;
            BattleBuddy._MySettings.Save();
        }


        private void trackBar3_ValueChanged(object sender, EventArgs e)
        {
            label3.Text = trackBar3.Value.ToString();
            BattleBuddy._MySettings.AdFactor = trackBar3.Value;
            BattleBuddy._MySettings.Save();
        }


        private void trackBar4_ValueChanged(object sender, EventArgs e)
        {
            label4.Text = trackBar4.Value.ToString();
            BattleBuddy._MySettings.DisFactor = trackBar4.Value;
            BattleBuddy._MySettings.Save();
        }


        private void trackBar5_ValueChanged(object sender, EventArgs e)
        {
            label10.Text = trkbarCombatDistance.Value.ToString();
            BattleBuddy._MySettings.Distance = trkbarCombatDistance.Value;
            BattleBuddy._MySettings.Save();
        }


        private void ListBuffs_Clicked(object sender, EventArgs e)
        {
            Lua.DoString("for j=1,C_PetBattles.GetNumAuras(1,C_PetBattles.GetActivePet(1)) do  local buffid = C_PetBattles.GetAuraInfo(1,1,j)  print (buffid) end");
        }


        private void comboBox11_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox11.SelectedIndex == -1)
            {
                button3.Enabled = false;
                button4.Enabled = false;
                comboBox2.Enabled = false;
                comboBox3.Enabled = false;
                comboBox4.Enabled = false;
                comboBox2.Items.Clear();
                comboBox3.Items.Clear();
                comboBox4.Items.Clear();
            }
            if (comboBox11.SelectedIndex > -1)
            {
                comboBox2.Enabled = true;
                if (comboBox3.Text == "") comboBox3.Enabled = false;
                if (comboBox4.Text == "") comboBox4.Enabled = false;

                if (comboBox2.Text == "") comboBox2.Items.Clear();

                for (int i = 0; i < options.Count(); i++)
                {
                    comboBox2.Items.Add(options[i]);
                    i++;
                    i++;
                }
            }
            SetBnB();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox3.Enabled = true;
            comboBox3.Text = "";
            comboBox3.Items.Clear();

            comboBox4.Enabled = true;
            comboBox4.Text = "";
            comboBox4.Items.Clear();


            string dumdumdum = comboBox2.Text;
            //Logging.Write("im here!!!"+dumdumdum);
            for (int i = 0; i < options.Count(); i++)
            {
                if (dumdumdum.Contains(options[i]))
                {

                    string[] equalizers = options[i + 1].Split(',');

                    foreach (string equalizer in equalizers)
                    {
                        comboBox3.Items.Add(equalizer);
                    }
                    string[] targetz = options[i + 2].Split(',');

                    foreach (string targ in targetz)
                    {
                        comboBox4.Items.Add(targ);
                    }

                }
                i++;
                i++;
            }
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox4.Text.Contains("NUMBER"))
            {
                if (comboBox11.Text != "" && comboBox2.Text != "" && comboBox3.Text != "" && comboBox4.Text != "")
                {
                    button3.Enabled = true;
                    button4.Enabled = true;
                }
            }

            if (comboBox4.Text.Contains("true"))
            {
                if (comboBox11.Text != "" && comboBox2.Text != "" && comboBox3.Text != "" && comboBox4.Text != "")
                {
                    button3.Enabled = true;
                    button4.Enabled = true;
                }
            }
            if (comboBox4.Text.Contains("false"))
            {
                if (comboBox11.Text != "" && comboBox2.Text != "" && comboBox3.Text != "" && comboBox4.Text != "")
                {
                    button3.Enabled = true;
                    button4.Enabled = true;
                }
            }

            if (comboBox11.SelectedIndex > -1)
            {
                if (comboBox11.Text != "" && comboBox2.Text != "" && comboBox3.Text != "" && comboBox4.Text != "")
                {
                    button3.Enabled = true;
                    button4.Enabled = true;
                }
            }
        }



        private void comboBox9_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //AND
            string dummy = comboBox2.Text.Replace("(X)", "(" + textBox101.Text + ")") + " " + comboBox3.Text + " " + comboBox4.Text.Replace("NUMBER", "" + textBox102.Text + "") + " $ ";
            textBox1.Text = textBox1.Text + dummy;
            //comboBox11.Enabled = false;
            comboBox2.SelectedIndex = -1;
            comboBox3.SelectedIndex = -1;
            comboBox4.SelectedIndex = -1;
            button3.Enabled = false;
            button4.Enabled = false;
            button2.Enabled = false;
        }



        private void button4_Click(object sender, EventArgs e)
        {
            //FINISH
            string dummy = comboBox11.Text + " " + textBox1.Text + comboBox2.Text.Replace("(X)", "(" + textBox101.Text + ")") + " " + comboBox3.Text + " " + comboBox4.Text.Replace("NUMBER", "" + textBox102.Text + "");
            textBox2.Text = dummy;
            textBox1.Text = "";
            comboBox2.SelectedIndex = -1;
            comboBox3.SelectedIndex = -1;
            comboBox4.SelectedIndex = -1;
            comboBox11.SelectedIndex = -1;
            comboBox2.SelectedIndex = -1;
            comboBox3.SelectedIndex = -1;
            comboBox4.SelectedIndex = -1;
            button2.Enabled = true;
        }


        private void AddToList(string s)
        {
            listBox1.Items.Add(s);
            return;
        }


        private void button2_Click(object sender, EventArgs e)
        {
            AddToList(textBox2.Text);
            button2.Enabled = false;
            textBox2.Text = "";
        }


        private void button99_Click(object sender, EventArgs e)
        {
        }



        private void button919_Click(object sender, EventArgs e)
        {
        }


        private void button929_Click(object sender, EventArgs e)
        {
        }

        private void button8_Click(object sender, EventArgs e)
        {
        }


        public void MoveItemPetRotate(int direction)
        {
            // Checking selected item
            if (lbRotationOrder.SelectedItem == null || lbRotationOrder.SelectedIndex < 0)
                return; // No selected item - nothing to do

            // Calculate new index using move direction
            int newIndex = lbRotationOrder.SelectedIndex + direction;

            // Checking bounds of the range
            if (newIndex < 0 || newIndex >= lbRotationOrder.Items.Count)
                return; // Index out of range - nothing to do

            object selected = lbRotationOrder.SelectedItem;

            // Removing removable element
            lbRotationOrder.Items.Remove(selected);
            // Insert it in new position
            lbRotationOrder.Items.Insert(newIndex, selected);
            // Restore selection
            lbRotationOrder.SetSelected(newIndex, true);
        }



        public void MoveItem(int direction)
        {
            // Checking selected item
            if (listBox1.SelectedItem == null || listBox1.SelectedIndex < 0)
                return; // No selected item - nothing to do

            // Calculate new index using move direction
            int newIndex = listBox1.SelectedIndex + direction;

            // Checking bounds of the range
            if (newIndex < 0 || newIndex >= listBox1.Items.Count)
                return; // Index out of range - nothing to do

            object selected = listBox1.SelectedItem;

            // Removing removable element
            listBox1.Items.Remove(selected);
            // Insert it in new position
            listBox1.Items.Insert(newIndex, selected);
            // Restore selection
            listBox1.SetSelected(newIndex, true);
        }



        private void button1_Click(object sender, EventArgs e)
        {
            string filename = BattleBuddy.GetPetSettingsFilePath(label71.Text);
            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
            listBox1.Items.Clear();
            BattleBuddy.LoadPetSettings(label71.Text, label22.Text);
            //string dumdum = "";
            string dumdum = BattleBuddy._PetSettings.Logic;
            string[] PetLogics = dumdum.Split('@');
            foreach (string alogic in PetLogics)
            {
                AddToList(alogic);
            }
        }


        private void button5_Click(object sender, EventArgs e)
        {
            MoveItem(-1);
        }



        private void button6_Click(object sender, EventArgs e)
        {
            MoveItem(1);
        }



        private void button7_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex > -1) listBox1.Items.Remove(listBox1.SelectedItem);

        }



        private void button10_Click(object sender, EventArgs e)
        {
        }


        private string GetPetImage(int slot)
        {
            List<string> cnt2 = Lua.GetReturnValues("local petid = C_PetJournal.GetPetLoadOutInfo(" + slot + ") local speciesID, customName, _, _, _,_, name, icon  = C_PetJournal.GetPetInfoByPetID(petid) return icon");
            string baseurl = "http://wow.zamimg.com/images/wow/icons/large/";
            string replace1 = @"INTERFACE\ICONS\";

            string image = cnt2[0].Replace(replace1, "").Replace(".BLP", "").ToLower();
            image = baseurl + image + ".jpg";
            return (image);
        }

        private void button11_Click(object sender, EventArgs e)
        {
        }



        private void SavePetSpecific()
        {
            if (label71.Text != "")
            {
                string dummy = "";

                int i = 0;
                foreach (object item in listBox1.Items)
                {
                    dummy = dummy + item.ToString();
                    if (i < listBox1.Items.Count - 1) dummy = dummy + "@";
                    i++;
                }
                //local petID, ability1ID, ability2ID, ability3ID, locked = C_PetJournal.GetPetLoadOutInfo(i) return ability1ID, ability2ID, ability3ID

                BattleBuddy.LoadPetSettings(label71.Text, label22.Text);
                List<string> cnt1 = Lua.GetReturnValues("for i=1,3 do local petID, ability1ID, ability2ID, ability3ID, locked = C_PetJournal.GetPetLoadOutInfo(i) if (tonumber(petID,16)==" + label71.Text + ") then return ability1ID, ability2ID, ability3ID end end return 0,0,0");
                string spelllayout = "ASSIGNABILITY1(" + cnt1[0] + ")@" +
                                     "ASSIGNABILITY2(" + cnt1[1] + ")@" +
                                     "ASSIGNABILITY3(" + cnt1[2] + ")";
                BattleBuddy._PetSettings.SpellLayout = spelllayout;
                BattleBuddy._PetSettings.Logic = dummy;
                BattleBuddy._PetSettings.Save();
            }
        }



        private void SaveSpecies()
        {
            if (label71.Text != "")
            {
                string dummy = "";

                int i = 0;
                foreach (object item in listBox1.Items)
                {
                    dummy = dummy + item.ToString();
                    if (i < listBox1.Items.Count - 1) dummy = dummy + "@";
                    i++;
                }
                BattleBuddy.LoadPetSettingsBN(label22.Text);

                List<string> cntskillz = Lua.GetReturnValues("for i=1,3 do local petID, ability1ID, ability2ID, ability3ID, locked = C_PetJournal.GetPetLoadOutInfo(i) if (tonumber(petID,16)==" + label71.Text + ") then return ability1ID, ability2ID, ability3ID end end return 0,0,0");
                string spelllayout = "ASSIGNABILITY1(" + cntskillz[0] + ")@" +
                                     "ASSIGNABILITY2(" + cntskillz[1] + ")@" +
                                     "ASSIGNABILITY3(" + cntskillz[2] + ")";
                BattleBuddy._PetSettings.SpellLayout = spelllayout;
                BattleBuddy._PetSettings.Logic = dummy;
                BattleBuddy._PetSettings.Save();

                Lua.DoString("C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_FAVORITES, false) C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_COLLECTED, true) C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_NOT_COLLECTED, true) ");
                Lua.DoString("C_PetJournal.ClearSearchFilter() C_PetJournal.AddAllPetSourcesFilter() C_PetJournal.AddAllPetTypesFilter() ");
                List<string> cnt1 = Lua.GetReturnValues("local teller=0 local retdata={} retdata[0]='nothing' retdata[1]='nothing'  local dummy1 = '" + BattleBuddy.GetSpeciesByName(label22.Text) + "' local numpets = C_PetJournal.GetNumPets(false) local skillist = C_PetJournal.GetPetAbilityList(dummy1); for j = 1, numpets do  local _, dummy2 = C_PetJournal.GetPetInfoByIndex(j,false); local skillist2 = C_PetJournal.GetPetAbilityList(dummy2); if skillist[1] == skillist2[1] and skillist[2] == skillist2[2] and skillist[3] == skillist2[3] then  local _,_,_,_,_,_,_,ass = C_PetJournal.GetPetInfoByIndex(j,false) teller=teller+1 retdata[teller]=ass end end return teller");
                int getal = 0;
                try
                {
                    getal = int.Parse(cnt1[0]);
                }
                catch (Exception exc)
                {
                    BBLog.LogException(exc);
                }
                for (int intI = 1; intI < getal; intI++)
                {
                    List<string> cnt = Lua.GetReturnValues("local teller=0 local retdata={} retdata[0]='nothing' retdata[1]='nothing'  local dummy1 = '" + BattleBuddy.GetSpeciesByName(label22.Text) + "' local numpets = C_PetJournal.GetNumPets(false) local skillist = C_PetJournal.GetPetAbilityList(dummy1); for j = 1, numpets do  local _, dummy2 = C_PetJournal.GetPetInfoByIndex(j,false); local skillist2 = C_PetJournal.GetPetAbilityList(dummy2); if skillist[1] == skillist2[1] and skillist[2] == skillist2[2] and skillist[3] == skillist2[3] then  local _,speciesID,_,_,_,_,_,ass = C_PetJournal.GetPetInfoByIndex(j,false) teller=teller+1 retdata[teller]=speciesID end end return (retdata[" + intI + "])");
                    cnt[0] = BattleBuddy.GetNameBySpeciesID(cnt[0]);
                    string filename = BattleBuddy.GetPetSettingsFilePath(cnt[0]);
                    if (!File.Exists(filename))
                    {

                        string filename2 = BattleBuddy.GetPetSettingsFilePath(label22.Text);
                        if (File.Exists(filename2))
                        {
                            File.Copy(filename2, filename);
                        }
                    }
                    Logging.Write(cnt[0]);
                }
            }
        }



        private void SaveNOverwrite()
        {
            //BattleBuddy pok = new BattleBuddy();
            if (label71.Text != "")
            {
                string dummy = "";

                int i = 0;
                foreach (object item in listBox1.Items)
                {
                    dummy = dummy + item.ToString();
                    if (i < listBox1.Items.Count - 1) dummy = dummy + "@";
                    i++;
                }

                BattleBuddy.LoadPetSettingsBN(label22.Text);

                List<string> cntskillz = Lua.GetReturnValues("for i=1,3 do local petID, ability1ID, ability2ID, ability3ID, locked = C_PetJournal.GetPetLoadOutInfo(i) if (tonumber(petID,16)==" + label71.Text + ") then return ability1ID, ability2ID, ability3ID end end return 0,0,0");
                string spelllayout = "ASSIGNABILITY1(" + cntskillz[0] + ")@" +
                                     "ASSIGNABILITY2(" + cntskillz[1] + ")@" +
                                     "ASSIGNABILITY3(" + cntskillz[2] + ")";

                BattleBuddy._PetSettings.SpellLayout = spelllayout;
                BattleBuddy._PetSettings.Logic = dummy;
                BattleBuddy._PetSettings.Save();

                Lua.DoString("C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_FAVORITES, false) C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_COLLECTED, true) C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_NOT_COLLECTED, true) ");
                Lua.DoString("C_PetJournal.ClearSearchFilter() C_PetJournal.AddAllPetSourcesFilter() C_PetJournal.AddAllPetTypesFilter() ");
                List<string> cnt1 = Lua.GetReturnValues("local teller=0 local retdata={} retdata[0]='nothing' retdata[1]='nothing'  local dummy1 = C_PetJournal.GetPetInfoByPetID(string.format('%X'," + label71.Text + ")); local numpets = C_PetJournal.GetNumPets(false) local skillist = C_PetJournal.GetPetAbilityList(dummy1); for j = 1, numpets do  local _, dummy2 = C_PetJournal.GetPetInfoByIndex(j,false); local skillist2 = C_PetJournal.GetPetAbilityList(dummy2); if skillist[1] == skillist2[1] and skillist[2] == skillist2[2] and skillist[3] == skillist2[3] then  local _,_,_,_,_,_,_,ass = C_PetJournal.GetPetInfoByIndex(j,false) teller=teller+1 retdata[teller]=ass end end return teller");
                int getal = 0;
                try
                {
                    getal = int.Parse(cnt1[0]);
                }
                catch (Exception exc)
                {
                    BBLog.LogException(exc);
                }

                Lua.DoString("C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_FAVORITES, false) C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_COLLECTED, true) C_PetJournal.SetFlagFilter(LE_PET_JOURNAL_FLAG_NOT_COLLECTED, true) ");
                Lua.DoString("C_PetJournal.ClearSearchFilter() C_PetJournal.AddAllPetSourcesFilter() C_PetJournal.AddAllPetTypesFilter() ");
                for (int intI = 1; intI < getal; intI++)
                {
                    List<string> cnt = Lua.GetReturnValues("local teller=0 local retdata={} retdata[0]='nothing' retdata[1]='nothing'  local dummy1 = '" + BattleBuddy.GetSpeciesByName(label22.Text) + "' local numpets = C_PetJournal.GetNumPets(false) local skillist = C_PetJournal.GetPetAbilityList(dummy1); for j = 1, numpets do  local _, dummy2 = C_PetJournal.GetPetInfoByIndex(j,false); local skillist2 = C_PetJournal.GetPetAbilityList(dummy2); if skillist[1] == skillist2[1] and skillist[2] == skillist2[2] and skillist[3] == skillist2[3] then  local _,speciesID,_,_,_,_,_,ass = C_PetJournal.GetPetInfoByIndex(j,false) teller=teller+1 retdata[teller]=speciesID  end end return (retdata[" + intI + "])");
                    //Logging.Write(cnt[0]);
                    cnt[0] = BattleBuddy.GetNameBySpeciesID(cnt[0]);
                    string filename = BattleBuddy.GetPetSettingsFilePath(cnt[0]);
                    string filename2 = BattleBuddy.GetPetSettingsFilePath(label22.Text);
                    //Logging.Write("File 1 : "+filename+ " File 2 :"+filename2);
                    if (File.Exists(filename) && filename != filename2) File.Delete(filename);

                    //string filename2=Application.StartupPath + "\\Plugins\\BattleBuddy\\PetSettings\\"+pok.GetNameByID(label71.Text)+".xml";
                    if (File.Exists(filename2) && filename != filename2)
                    {
                        File.Copy(filename2, filename);
                    }
                    Logging.Write(cnt[0]);
                }
            }
        }


        private void button44_Click(object sender, EventArgs e)
        {
        }


        private void cbForfeitNonInteresting_CheckedChanged(object sender, EventArgs e)
        {
            BattleBuddy._MySettings.ForfeitIfNotInteresting = cbForfeitNonInteresting.Checked;
            BattleBuddy._MySettings.Save();
        }


        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
        }


        private void cbDetailedLogging_CheckedChanged(object sender, EventArgs e)
        {
            BattleBuddy._MySettings.DetailedLogging = cbDetailedLogging.Checked;
            BattleBuddy._MySettings.Save();
        }


        private void cmbBattleLowerLimit_SelectedIndexChanged(object sender, EventArgs e)
        {
            BattleBuddy._MySettings.BelowLevel = cmbBattleLowerLimit.SelectedIndex;
            BattleBuddy._MySettings.Save();
        }


        private void cmbBattleUpperLimit_SelectedIndexChanged(object sender, EventArgs e)
        {
            BattleBuddy._MySettings.AboveLevel = cmbBattleUpperLimit.SelectedIndex;
            BattleBuddy._MySettings.Save();
        }

        private void cmbMinPvpTime_SelectedIndexChanged(object sender, EventArgs e)
        {
            BattleBuddy._MySettings.PVPMinTime = cmbMinPvpTime.SelectedIndex;
            if (initdone == 1)
            {
                cmbMaxPvpTime.Items.Clear();
                int dummy = 0;
                for (int i = 1; i < 60; i++)
                {
                    dummy = cmbMinPvpTime.SelectedIndex + 1;
                    cmbMaxPvpTime.Items.Add(dummy + i);
                }
                cmbMaxPvpTime.SelectedIndex = 0;
            }
            BattleBuddy._MySettings.Save();
        }


        private void cmbMaxPvpTime_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (initdone == 1) BattleBuddy._MySettings.PVPMaxTime = cmbMaxPvpTime.SelectedIndex;
            if (initdone == 0) cmbMaxPvpTime.SelectedIndex = BattleBuddy._MySettings.PVPMaxTime;
            BattleBuddy._MySettings.Save();
        }


        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            BattleBuddy._MySettings.DoPVP = checkBox1.Checked;
            BattleBuddy._MySettings.Save();
        }


        private void button45_Click(object sender, EventArgs e)
        {
        }
    }
}




